#pragma once

#include "UMLInteractionDiagram.h"

#include "../uml/Interaction.h"

namespace uml {

const bool UMLInteractionDiagram::isLifelineDashed_default_ = false;
UMLInteractionDiagram::UMLInteractionDiagram(const QString& umlType)
    : UMLDiagram(umlType) {}

void UMLInteractionDiagram::fromJson(const QJsonObject& json, QStringList& errorList) {
    if (json.isEmpty()) {
        return;
    }

    UMLDiagram::fromJson(json, errorList);
    UMLBehaviorDiagram::fromJson(json, errorList);
    modelElement_ = JsonSerializable::create<Interaction>(json.value("modelElement"), errorList);

    kind_ = (UMLInteractionDiagramKind)json.value("kind").toInt((int)kind_);
    isLifelineDashed_ = json.value("isLifelineDashed").toBool(isLifelineDashed_default_);
}

void UMLInteractionDiagram::toJson(QJsonObject& json) {
    UMLDiagram::toJson(json);
    UMLBehaviorDiagram::toJson(json);
    if (modelElement_) {
        QJsonObject modelElement_json;
        modelElement_->toJson(modelElement_json);
        json.insert("modelElement", modelElement_json);
    }
    json.insert("kind", (int)kind_);
    if (isLifelineDashed_ != isLifelineDashed_default_) {
        json.insert("isLifelineDashed", isLifelineDashed_);
    }
}

/// <summary>
/// modelElement getter
/// Restricts UMLInteractionDiagrams to showing Interactions.
/// </summary>
shared_ptr<Interaction> UMLInteractionDiagram::modelElement() const {
    return modelElement_;
}

/// <summary>
/// modelElement setter
/// Restricts UMLInteractionDiagrams to showing Interactions.
/// </summary>
void UMLInteractionDiagram::setModelElement(shared_ptr<Interaction> value) {
    modelElement_ = value;
}

/// <summary>
/// kind getter
/// Indicates how an Interaction shall be shown.
/// </summary>
UMLInteractionDiagramKind UMLInteractionDiagram::kind() const {
    return kind_;
}

/// <summary>
/// kind setter
/// Indicates how an Interaction shall be shown.
/// </summary>
void UMLInteractionDiagram::setKind(UMLInteractionDiagramKind value) {
    kind_ = value;
}

/// <summary>
/// isLifelineDashed getter
/// Indicates whether lifelines on the diagram shall be rendered as dashed.
/// </summary>
bool UMLInteractionDiagram::isLifelineDashed() const {
    return isLifelineDashed_;
}

/// <summary>
/// isLifelineDashed setter
/// Indicates whether lifelines on the diagram shall be rendered as dashed.
/// </summary>
void UMLInteractionDiagram::setIsLifelineDashed(bool value) {
    isLifelineDashed_ = value;
}

} // namespace uml
